package com.ruoyi.web.controller.fs;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fs.domain.FsEntrust;
import com.ruoyi.fs.service.IFsEntrustService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 委托方Controller
 * 
 * @author hero
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/fs/entrust")
public class FsEntrustController extends BaseController
{
    @Autowired
    private IFsEntrustService fsEntrustService;

    /**
     * 查询委托方列表
     */
    @PreAuthorize("@ss.hasPermi('fs:entrust:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsEntrust fsEntrust)
    {
        startPage();
        List<FsEntrust> list = fsEntrustService.selectFsEntrustList(fsEntrust);
        return getDataTable(list);
    }

    /**
     * 导出委托方列表
     */
    @PreAuthorize("@ss.hasPermi('fs:entrust:export')")
    @Log(title = "委托方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FsEntrust fsEntrust)
    {
        List<FsEntrust> list = fsEntrustService.selectFsEntrustList(fsEntrust);
        ExcelUtil<FsEntrust> util = new ExcelUtil<FsEntrust>(FsEntrust.class);
        util.exportExcel(response, list, "委托方数据");
    }

    /**
     * 获取委托方详细信息
     */
    @PreAuthorize("@ss.hasPermi('fs:entrust:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fsEntrustService.selectFsEntrustById(id));
    }

    /**
     * 新增委托方
     */
    @PreAuthorize("@ss.hasPermi('fs:entrust:add')")
    @Log(title = "委托方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsEntrust fsEntrust)
    {
        fsEntrust.setCaseCount(0);
        fsEntrust.setBatchCount(0);
        fsEntrust.setWtze(BigDecimal.ZERO);
        return toAjax(fsEntrustService.insertFsEntrust(fsEntrust));
    }

    /**
     * 修改委托方
     */
    @PreAuthorize("@ss.hasPermi('fs:entrust:edit')")
    @Log(title = "委托方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsEntrust fsEntrust)
    {
        return toAjax(fsEntrustService.updateFsEntrust(fsEntrust));
    }

    /**
     * 删除委托方
     */
    @PreAuthorize("@ss.hasPermi('fs:entrust:remove')")
    @Log(title = "委托方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsEntrustService.deleteFsEntrustByIds(ids));
    }
}
